package com.student.advice;

import com.student.service.FileUploadService;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Aspect
@Component
public class DownloadFileAspect {

    @Resource
    private FileUploadService fileUploadService;

    @Pointcut("execution(public void com.student.controller.FileUploadController.downloadFile(..))")
    public void downloadFile() {}

    // 在下载文件方法执行前，统计下载次数  （AOP）
    @Before("downloadFile() && args(fileId,..)")
    public void incrementDownloadCount(int fileId) {
        System.out.println("incrementDownloadCount");
        fileUploadService.incrementDownloadCount(fileId);  // 增加下载次数
    }
}
